import "../static/libs/flexible"
import "../scss/common.scss"
import "../scss/register.scss"
import http from "../utils/http"

function main() {
    register() //注册
    toLogin() //点击跳转登录
    seePwd() //点击查看密码
    jump()  //跳转
}
main()

//注册
function register() {
    $(".center .ljdl").on("click", async function () {
        const name = $(".dl .username").val()
        const password = $(".dl .pwd").val()
        const confirmPwd = $(".dl .surepwd").val()
        if (name && password && confirmPwd) {
            if (confirmPwd == password) {
                const data = await http({ url: "/users/register", data: { name, password }, method: "POST" })
                if (data.code == 1) {
                    window.location.assign("./login.html")
                } else {
                    alert("注册失败")
                }
            } else {
                alert("两次密码不一致")
            }
        } else {
            alert("输入不能为空")
        }
    })
}

//点击跳转登录
function toLogin() {
    $(".center .zc").on("click", function () {
        window.location.assign("./login.html")
    })
}

//点击查看密码
function seePwd() {
    $(".dl .eye").on("click", function () {
        $(this).prev().attr("type", "text")
        setTimeout(function () {
            $(".pwd").attr("type", "password")
        }, 1500)
    })
}

//点击跳转
function jump() {
    $(".header .head_right").on("click", function () {
        if ($(".header .wrapper").css("display") == "none") {
            $(".header .wrapper").css("display", "block")
            $(".header .wrapper .menu li").on("click", function () {
                const text = $(this).text()
                console.log(text);
                if (text == "首页") {
                    window.location.assign("index.html")
                } else if (text == "错题本") {
                    window.location.assign("errors.html")
                } else if (text == "收藏夹") {
                    window.location.assign("collection.html")
                } else if (text == "登录") {
                    window.location.assign("login.html")
                } else if (text == "个人中心") {
                    window.location.assign("personalCenter.html")
                }
            })
        } else {
            $(".header .wrapper").css("display", "none")
        }
    })
}